package com.loadmore.common.base

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.loadmore.common.R
import com.luck.picture.lib.tools.ScreenUtils

class BaseDecoration : RecyclerView.ItemDecoration {
    lateinit var paint: Paint
    lateinit var context: Context
    constructor(context: Context) {
        this.context = context
        paint = Paint()
        paint.color = context.resources.getColor(R.color.list_color)
        paint.strokeWidth = 1f
    }
    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        super.getItemOffsets(outRect, view, parent, state)
        outRect.top = 0

    }

    override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
        super.onDrawOver(c, parent, state)
        var count = parent.childCount
        for (i in 0 until count) {
            var view:View = parent.getChildAt(i)
            var pos = parent.getChildAdapterPosition(view)
            c.drawLine(0f, view.bottom.toFloat(), ScreenUtils.getScreenWidth(context).toFloat(), view.bottom.toFloat(),paint)
        }
    }
}